package ch.drshit.view.swing;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;

public class MyJComponent extends JComponent {

	private static final long serialVersionUID = -304469272459391056L;
	private BufferedImage bf;
	private float zoomlevel;
	private int xadjust;
	private int yadjust;

	public MyJComponent() {
		this.zoomlevel = 1.0f;
		this.xadjust = 0;
		this.yadjust = 0;
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		if (this.bf != null) {
			Dimension realsize = this.getRealSize();
			int xtmp = this.xadjust;
			int ytmp = this.yadjust;

			g.drawImage(this.bf, xtmp, ytmp, (int) realsize.width,
					(int) realsize.height, null);
		}
	}

	public void setBF(BufferedImage bf) {
		this.bf = bf;
	}
	
	public boolean hasBF(){
		return this.bf != null;
	}

	public void upZoomlevel() {
		this.zoomlevel += 0.1f;
	}

	public void downZoomlevel() {
		if (this.zoomlevel - 0.1f > 0) {
			this.zoomlevel -= 0.1f;
		}
	}
	
	public float getZoomlevel(){
		return this.zoomlevel;
	}

	public Dimension getRealSize() {
		float width = this.bf.getWidth() * this.zoomlevel;
		float height = this.bf.getHeight() * this.zoomlevel;
		return new Dimension((int) width, (int) height);
	}

	public void setXadjust(int value) {
		this.xadjust = value;
	}
	
	public int getXadjust(){
		return this.xadjust;
	}

	public void setYadjust(int value) {
		this.yadjust = value;
	}
	
	public int getYadjust(){
		return this.yadjust;
	}
}
